package com.twu.biblioteca.ui.menus;

import com.twu.biblioteca.BibliotecaApp;
import com.twu.biblioteca.app.Library;

import java.io.BufferedReader;
import java.io.IOException;

public class ReturnBookMenu {

    private BufferedReader br;

    public ReturnBookMenu(BufferedReader br) {
        this.br = br;
    }

    public String getMenuOptions() {
        return("Please enter the title of the book you would like to return:");
    }

    public Library readTitleAndReturnBook(Library library) {
        try {
            String input = br.readLine();
            if (library.returnBook(input)) {
                displaySuccessfulCheckoutMessage();
            } else {
                displaySelectionError();
            }

        } catch (IOException e) {
            System.out.println("There was an error reading from the provided input reader.");
            BibliotecaApp.exit();
        }

        return library;
    }

    public void displaySuccessfulCheckoutMessage() {
        System.out.print("Thank you for returning the book.\n");
    }

    public void displaySelectionError() {
        System.out.print("That is not a valid book to return.\n");
    }
}
